<template>
  <van-picker
    title="性别"
    show-toolbar
    :columns="columns"
    :default-index='genders'
    @cancel="$emit('close')"
    @change="onChange"
    @confirm="onConfirm"
  />
</template>

<script>
import { updateUserProfile } from '@/api/user'
export default {
  data () {
    return {
      columns: ['男', '女'],
      gender: 1
    }
  },
  props: {
    genders: {
      type: [Number, String, Object],
      required: true
    }
  },
  created () {
  },
  methods: {
    onChange (picker, value, index) {
      this.gender = index
    },
    async onConfirm () {
      this.$toast.loading({
        message: '保存中....',
        forbidClick: true,
        duration: 0
      })
      try {
        await updateUserProfile({
          gender: this.gender
        })
        this.$toast('修改成功')
      } catch (error) {
        this.$toast('修改失败')
      }
      this.$emit('close')
    }
  }
}
</script>
<style scoped lang='less'>

</style>
